package br.com.fidalgotecnologia.layar.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.fidalgotecnologia.layar.CtrlLayar.CtrlLayar;
import br.com.fidalgotecnologia.layar.entity.Layer;

/**
 * Servlet implementation class LayerServlet
 */
@WebServlet("/LayerServlet")
public class LayerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LayerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Layer layer = new Layer();
		layer.setId(Long.parseLong(request.getParameter("id")));
		response.setContentType("application/json");
		// Get the printwriter object from response to write the required json object to the output stream      
		PrintWriter out = response.getWriter();
		// Assuming your json object is **jsonObject**, perform the following, it will return your json object  
		out.print(CtrlLayar.getInstance().writeJson(layer));
		out.flush();

	}

}
